welcome back to module of Data Warehouse OLAP and Data Cube so in this tutorial we are going to learn how to use panda's pivot table to manage your data as a data warehouse and before we get into the details I would like to briefly introduce you the major difference between OLTP which is online transaction processing and OLAP which is online analytical processing the second one OLAP is actually used for data warehouse so think about the scenario that if you are just want to record transactions you just want to collect data from the first hand casher then everything you do to design a database to record the transactions to combine transactions is for a smooth and accurate in collecting your data so that is the purpose for OLTP however many times as a data scientist you actually need to use your data for data analysis and that data analysis we will need it for decision making basically that is the purpose of OLAP or that is the reason we have to separate our data from our normal data routine as collection to data warehouse, and in the data warehouse we are going to store a data with a much longer history because we want to do the comparison between now and in the past can help us to have some insights into the future so that will be another course if you just want to know data warehouse and I will leave you to explore that topic and for the pivot_table basically we can manipulate the dataframe and then prepare something for the data warehouse style and we're going to learn more about the data cube for the setup we are going to import Numpy as np import pandas as pd so this time we are going to use our Spotify YouTube sample CSV which I have already uploaded it here so you are going to download this file in this lesson and then upload it to the file area of Google Collaboratory you can either drop it here or you can use this button to upload the file from the device after that you can click the 3 dots copy the path and then paste it here then you will be able to again read the data from the CSV and load it into your data frame let's have a look on the structure of this data frame basically we have 10 columns and we have 20,718 records those are the things we have already worked on before and here we are going to re-vist it so as you can see here for artists we have the unique value we learned that we have 2000 more artists in this huge dataset so I just print out the first 100 out so that we can use some of the names first of all let's create a pivot_table so pivot_table you will see directly here what it is because our OLAP is based on analytical reason for the decision making so we need to organize our data in a way that we can draw insights based on and around the interest in this example the interest will be the values we can specify here because we just want to know exactly what is the views what is the likes what is the comments because we want to know or we want to examine the popularity of the artist and the popularity of certain album so that will be the thing we would like to know so in this case if we are going to prepare a data warehouse our interest will be the values that will be the views likes comments our dimension which we can see exactly here that will be artist and album so that you can see that once we do this pivot table our data frame will be converted into a category with super category and sub category in terms of the dimensions and each of the category will have the comments likes and views that they are our interest the aggregation function in here you can specify you want to know the mean if you want to know the average performance if you want to know the total then you can actually just sum up every single value you have so this will be a pivot table and as you can see this is actually an organized structure with all kinds of dimensions listed here and entries listed in this place let's play with this part of the table and see how we can get insights from it for example use this part of the table you can easily locate Michael Jackson because we organized our dimensions as first one as artist second one as album so we can easily see in this particular artist the album will be our first category and for each of the album we can see directly the comments the likes the views because one album may have multiple songs and these comments and the likes and the views in this particular part of the table is the mean of the performance of the songs etc and we can use the locate to select multiple artists as well for example Michael Jackson, The Beatles, and Beyonce for this selection we actually will have a comparison of them for example this will be all the albums belongs to Michael Jackson and this will be all the albums belongs to Beyonc and again for each of the album we aggregated the mean of all the songs in that album now we have the mean, and we have the sense of how and why and the motivation we need the powered table let's look into another way of making it even more useful that is the sorting because without the sorting everything is just scattered around but with the sorting for example if we just sort everything by views now the views were dominating everything then we can see that Daddy Yankee has a album has the largest meaning of the views that will actually draw some attention to this particular artist and make this particular album as well and we can even have the setting equal defaults with the artist and the view together because these are the dimensions we can do then we can see that for every artist we are sorting the views and then we see that this snowfall is the most successful album in terms of the mean of the views of this artist and again we can also select the certain interest artists you may want to examine more like I just draw attention to the Daddy Yankee and then I can immediately see that for this particular artist we can see the VIDA is the most successful album and this artist actually has many more and that can give us a list to do further examination if you are really a classic music lover then maybe you are going to check out the Coldplay in comparison with the Beatles then we can see that for the Coldplay we actually have this album most successful again in terms of the views in terms of the mean of our aggregation function and for the Beatles we can have another list they are sorting the based on the views so this pivot table using the aggregation using the interest and value and using the sort can help you to find a lot of insights from rather a plain and a spreadout data frame so as a practice I would like to ask you to do to change some of the things in our tutorial first of all select some of other entries that you may like not just review the likes and the comments also if you would like to go further not just the artist and album maybe you can try some other things such as the album type such as the Track such as the official video, etc. as long as you can make them more dimensions because we're going to learn the dimensionality in our data cube later on but here at least you know the more dimension you have the more structure you can have and the more details you can have the last thing you can change is the aggregation function so here we use the mean but definitely you can change it to the sum etc and I will leave that for you to play with this data set I'll see you later on